package PersonStu.siqi;

/**
 * @Author: Dijah
 * @Date: 2023/7/21 15:35
 * @Desc: 给定一个整数数组，求子数组的最大累加和
 */
public class code05_maxSubArray {

    public static int maxSubArray(int [] nums){
        int [] dp = nums;
        int max = nums[0];
        for(int i = 1; i < nums.length; i++){
            dp[i] = Math.max(nums[i],nums[i] + dp[i-1]);
            max = Math.max(dp[i],max);
        }
        return max;
    }

    public static void main(String[] args) {
        int [] nums = {1,3,-9,6,4,-4};
        int i = maxSubArray(nums);
        System.out.println(i);
    }
}
